#include "MoveHandler.h"

MoveHandler::MoveHandler(Movable* receiver): movable(receiver)
{
}

MoveHandler::MoveHandler(const MoveHandler& rhs): movable(rhs.movable)
{
}


MoveHandler::~MoveHandler()
{
}

GameEventHandler* MoveHandler::Clone() const
{
	return new MoveHandler(*this);
}

bool MoveHandler::CanHandle(const GameEvent* gameEvent) const
{
	return movable && gameEvent->Equals(&moveEvent);
}

void MoveHandler::HandleEvent(GameEvent* gameEvent)
{
	if (movable && gameEvent->Equals(&moveEvent))
	{
		moveEvent.Copy(gameEvent);

		switch(moveEvent.MoveDirection().Type())
		{
			case Direction::NORTH:
				movable->MoveUp();
			break;

			case Direction::WEST:
				movable->MoveLeft();
			break;

			case Direction::SOUTH:
				movable->MoveDown();
			break;

			case Direction::EAST:
				movable->MoveRight();
			break;
		}
	}
}
